package com.tanqing.ddd.web.service.impl;

import com.tanqing.ddd.domain.domain.DomainEvent;
import com.tanqing.ddd.domain.domain.DomainEventListener;
import com.tanqing.ddd.domain.event.CheckInEvent;
import com.tanqing.ddd.domain.event.CheckOutSuccessEvent;
import com.tanqing.ddd.web.entity.Summary;
import com.tanqing.ddd.web.mapper.SummaryMapper;
import com.tanqing.ddd.web.service.ISummaryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zs
 * @since 2024-01-14
 */
@Service
@Slf4j
public class SummaryServiceImpl extends ServiceImpl<SummaryMapper, Summary> implements ISummaryService, DomainEventListener {

    /**
     * 事件处理
     * @param event
     */
    @Override
    public void onEvent(DomainEvent event) {
        if (event instanceof CheckInEvent) {

            log.info("CheckInEvent  ");
            Summary summary = new Summary();
            summary.setTotalInParking(1);
            this.save(summary);
        }
        if (event instanceof CheckOutSuccessEvent) {
            log.info("CheckOutSuccessEvent  ");
            Summary summary = new Summary();
            summary.setTotalInParking(2);
            this.save(summary);
        }
    }
}
